﻿<UserControl x:Class="ScrumFactory.HelpDeskPlugin.HelpDesk"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"                          
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"                             
             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Helpers_Ext="clr-namespace:ScrumFactory.Windows.Helpers.Extensions;assembly=ScrumFactory.Windows.Helpers"
             
             xmlns:props="clr-namespace:ScrumFactory.HelpDeskPlugin.Properties"

             x:Name="thisView"
             
             SF_Comp:CommandBehavior.RoutedEventName="Loaded"
             SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}"

             HorizontalAlignment="Stretch" 
           
             
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.InputBindings>
        <KeyBinding Key="F5" Command="{Binding RefreshCommand}" />
    </UserControl.InputBindings>


    <UserControl.Resources>
        <CompositeCollection x:Key="taskCollection">
            <CollectionContainer Collection="{Binding DataContext.Tasks, Source={x:Reference taskList}}"/>
            <ListBoxItem Focusable="False">
                <StackPanel HorizontalAlignment="Stretch" Focusable="False">

                    <TextBlock 
                        Text="{x:Static props:Resources.press_Esc_to_cancel}" 
                        FontStyle="Italic" FontSize="{StaticResource SmallFontSize}" 
                        Focusable="False"
                        Foreground="Gray" HorizontalAlignment="Right" Margin="0,0,10,0">
                        <TextBlock.Style>
                            <Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsAddingTask}" Value="False">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>

                    <TextBox Text="{Binding NewTaskName, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" Height="100"                             
                             Focusable="True" FocusManager.IsFocusScope="True"
                             SF_Helpers_Ext:TextBoxExtension.IsFocused="{Binding IsFocusAtNewTask}">
                        <TextBox.Style>
                            <Style BasedOn="{StaticResource {x:Type TextBox}}" TargetType="TextBox">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsAddingTask}" Value="False">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBox.Style>
                        <TextBox.InputBindings>
                            <KeyBinding Key="Enter" Command="{Binding ConfirmAddTaskCommand}"/>
                            <KeyBinding Key="Esc" Command="{Binding CancelAddTaskCommand}"/>
                        </TextBox.InputBindings>
                    </TextBox>

                    <Button 
                        Command="{Binding AddTaskCommand}" Margin="0"
                        Focusable="False"
                        Content="{x:Static props:Resources.work_on_it}" Width="120" HorizontalAlignment="Left" 
                        Background="{StaticResource ActionButtonBackground}" >
                        <Button.Style>
                            <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsAddingTask}" Value="True">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>



                </StackPanel>
                
            </ListBoxItem>
        </CompositeCollection>
    </UserControl.Resources>
    
    <SF_Helpers:PanelLayout 
            ShowCurrentProjectName="False"            
            Title="{Binding PanelName}" Background="Transparent" BorderBrush="Transparent">

        <!-- TOOLBAR -->
        <SF_Helpers:PanelLayout.Toolbar>
            <Grid>            
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>

                <ToolBar Grid.Row="0" HorizontalAlignment="Stretch">


                    <MenuItem
                                IsEnabled="{Binding IsSignedMemberAtProject}"
                                Header="{x:Static props:Resources.New_ticket}" Focusable="False">
                        <MenuItem.Icon>
                            <Image Source="/Images/ToolBar/Add.png" Width="32" Height="32" Stretch="Uniform"/>
                        </MenuItem.Icon>

                        <MenuItem.Style>
                            <Style BasedOn="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}" TargetType="MenuItem">
                                <Style.Triggers>
                                    <Trigger Property="MenuItem.IsPressed" Value="True">
                                        <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=addTextBox}"/>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </MenuItem.Style>
                    </MenuItem>

                </ToolBar>


                <Grid x:Name="newItemPanel"
                            Grid.ColumnSpan="2" Grid.Row="1"
                            Style="{StaticResource NewItemPanelAutoClose}">
                    <DockPanel VerticalAlignment="Top" HorizontalAlignment="Stretch">
                        
                        <ComboBox
                            SelectedValue="{Binding NewTickectProject}"                        
                            Width="200" BorderBrush="{StaticResource TextBoxBackgroundBrush}"  VerticalAlignment="Center" DockPanel.Dock="Left"
                            ItemsSource="{Binding Projects}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>                                    
                                    <TextBlock Text="{Binding ProjectName}" HorizontalAlignment="Stretch" />                                    
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>

                        <TextBox      
                            x:Name="addTextBox"   VerticalAlignment="Center" DockPanel.Dock="Right"
                            ToolTip="{x:Static props:Resources.New_ticket_name}" BorderBrush="{StaticResource TextBoxBackgroundBrush}"
                            Text="{Binding NewTicketName, UpdateSourceTrigger=PropertyChanged}"                                                         
                            HorizontalAlignment="Stretch" />

                    </DockPanel>


                </Grid>
            </Grid>
        </SF_Helpers:PanelLayout.Toolbar>

        <SF_Helpers:PanelLayout.Content>
            
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width=".55*"/>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>

                <Grid Grid.Column="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Row="0">
                        <TextBlock Text="{Binding BacklogItems.Count, StringFormat={x:Static props:Resources.N_open_jobs}}" Style="{StaticResource TitleTextBlock}" />
                        <CheckBox IsChecked="{Binding OnlyMineProjects}" Content="{x:Static props:Resources.only_projects_im_envolved}"/>
                    </StackPanel>
                    

                    <ListBox                    
                        Grid.Row="1"
                        SelectedItem="{Binding SelectedItem}"
                        ItemsSource="{Binding BacklogItems}"
                        Margin="0,0,10,0">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="0,0,0,15">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>

                                    <Image DataContext="{Binding HasArtifact}" Style="{StaticResource HasArtifactImage}" Grid.ColumnSpan="4" VerticalAlignment="Top" HorizontalAlignment="Right"/>

                                    <Image Grid.Column="0" Style="{StaticResource BacklogItemStatusImage}" DataContext="{Binding Item.Status}" Width="24" Height="24" />
                                    <Image Grid.Column="1" DataContext="{Binding Item.IssueType}" Style="{StaticResource IssueImage}" Width="24" Height="24" Margin="5,0,5,0"/>
                                    
                                    <StackPanel Grid.Column="2" Orientation="Vertical" >
                                        <TextBlock Style="{StaticResource ItemTitleTextBlock}" Foreground="{StaticResource LabelBrush}">
                                            <Run Text="{Binding Item.Name}" />
                                            <Run Text="#" Foreground="{StaticResource HighlightTextBrush}"/><Run Text="{Binding TrackId, Mode=OneWay}" Foreground="{StaticResource HighlightTextBrush}"/><Run Text="#" Foreground="{StaticResource HighlightTextBrush}"/>
                                        </TextBlock>
                                        
                                        <TextBlock>
                                            <Run Text="{Binding Item.Project.ClientName}"/>
                                            <Run Text="-"/>
                                            <Run Text="{Binding Item.Project.ProjectName}"/>
                                        </TextBlock> 
                                        
                                        
                                        

                                    </StackPanel>

                                    <TextBlock 
                                        Grid.Column="3"
                                        HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center"
                                        Foreground="{StaticResource HighlightTextBrush}" FontSize="{StaticResource ReallyBigFontSize}"
                                        Text="{Binding Item.CreateDate, Converter={StaticResource ContextDateConverter}, ConverterParameter=True}" />
                                    
                                    

                                </Grid>
                              
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    

                </Grid>
                

         

                <Border Padding="10,10,10,0" Grid.Column="1" Background="White" MinWidth="600">
                    <Grid>

                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        
                        <StackPanel Grid.Row="0">
                            <Button Content="{x:Static props:Resources.Close_job}" Command="{Binding CloseJobCommand}" Width="140" HorizontalAlignment="Right" Margin="0">
                                <Button.Style>
                                    <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
                                        <Style.Triggers>
                                            <Trigger Property="IsEnabled" Value="False">
                                                <Setter Property="Visibility" Value="Collapsed"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </Button.Style>
                            </Button>

                            <TextBlock Margin="0,0,0,5" >
                            <Hyperlink Command="{Binding ShowItemCommand}">
                                <TextBlock Text="{Binding SelectedItem.Item.Name}" FontSize="{StaticResource BigFontSize}" />    
                            </Hyperlink>
                        </TextBlock>

                            <TextBlock Text="{Binding SelectedItem.Item.Description}"/>

                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                <ContentControl DataContext="{Binding SelectedItem}" Style="{StaticResource BacklogItemProgressBarBorder}" Width="30" VerticalAlignment="Center" />
                                <TextBlock Foreground="{StaticResource LabelBrush}" FontWeight="Bold" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="10,0,0,0">
                                <TextBlock Text="{Binding SelectedItem.Item.CurrentTotalHours, Mode=OneWay, StringFormat='{}0.#'}" FontSize="{StaticResource ReallyBigFontSize}" ToolTip="{Binding PlannedHoursToolTip}"/>
                                <Run Text="{x:Static props:Resources.hrs}" FontSize="{StaticResource SmallFontSize}" />
                            </TextBlock>
                            </StackPanel>

                            <TextBlock Text="{x:Static props:Resources.Effort}" Foreground="Gray" Margin="5,8,0,0" />

                        </StackPanel>

                        
                        <ListBox x:Name="taskList" 
                                 Grid.Row="1"
                                 ItemContainerStyle="{StaticResource NoSelectionListBoxItem}"
                                 HorizontalContentAlignment="Stretch"
                                 ItemsSource="{StaticResource taskCollection}">                                   
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="0,0,0,10">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="auto"/>                                            
                                            <ColumnDefinition Width="400" />
                                            <ColumnDefinition Width="30"/>
                                            <ColumnDefinition Width="90"/>
                                        </Grid.ColumnDefinitions>

                                        <ContentControl 
                                            Grid.Column="0" 
                                            Style="{StaticResource MemberImageNoIndicatorControlStyle2}" DataContext="{Binding TaskAssigneeUId}"/>

                                        <StackPanel Grid.Column="1" Orientation="Vertical" Margin="10,0,0,0"  >
                                            <TextBlock TextWrapping="Wrap" TextTrimming="None">
                                                <Hyperlink Command="{Binding Model.ShowTaskCommand, ElementName=thisView}" CommandParameter="{Binding .}">
                                                    <Run Text="{Binding TaskName}" FontSize="{StaticResource BigFontSize}" />    
                                                </Hyperlink>
                                            </TextBlock>                                            
                                            <TextBlock Foreground="Gray" FontSize="{StaticResource SmallFontSize}">                                                
                                                <Run Text="{Binding CreatedAt, Mode=OneWay, Converter={StaticResource ContextDateConverter}, ConverterParameter=True}" />
                                                <Run Text="{x:Static props:Resources._by}"/>
                                                <Run Text="{Binding TaskAssigneeUId, Mode=OneWay}" FontStyle="Italic" />
                                            </TextBlock>
                                            
                                        </StackPanel>


                                        <Image Grid.Column="2"
                                               DataContext="{Binding Status}"
                                               Style="{StaticResource TaskStatusImage}"
                                               Width="24" Height="24"
                                               VerticalAlignment="Center" HorizontalAlignment="Center" />


                                        <TextBlock 
                                            Grid.Column="3" VerticalAlignment="Center"
                                             FontWeight="Bold" HorizontalAlignment="Right" Foreground="Gray">
                                                <TextBlock Text="{Binding EffectiveHours, Mode=OneWay, StringFormat='{}0.#'}" FontSize="{StaticResource ReallyBigFontSize}"/>
                                                <Run Text="{x:Static props:Resources.hrs}" FontSize="{StaticResource SmallFontSize}" />
                                        </TextBlock>

                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                        
                    </Grid>
                    
                    <Border.Style>
                        <Style TargetType="Border">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding SelectedItem}" Value="{x:Null}">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Border.Style>
                </Border>


                <ContentControl Grid.ColumnSpan="2"                                                
                            Style="{StaticResource LoadingAnimationContent}"/>


            </Grid>
            
                
            
        </SF_Helpers:PanelLayout.Content>
        
    </SF_Helpers:PanelLayout>
</UserControl>
